package ioc

import (
	"gitee.com/chicken-c/go-learn/webook/config"
	"gitee.com/chicken-c/go-learn/webook/internal/repostiory/dao"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func InitDB() *gorm.DB {
	//dsn := viper.GetString("db.mysql.dsn")
	//fmt.Println(dsn)

	db, err := gorm.Open(mysql.Open(config.Configs.DB.DSN), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	err = dao.InitTables(db)
	if err != nil {
		panic(err)
	}

	return db
}
